Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Update docs about Cache-Control default headers. #35336

Merged
merged 4 commits into from
Mar 16, 2022
Merged

[docs] Update docs about Cache-Control default headers. #35336

merged 4 commits into from
Mar 16, 2022

Conversation

Gomurmamma
Copy link
Contributor

Closes #33210.

This PR fixes #33210 with an update to the going-to-production.md file about how Cache-Control headers are set by default based on how a page requests data.

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running yarn lint

Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Could we also mention the part how you can override the default in case of gSSP?:

If you want a different Cache-Control while using SSR you can use res.setHeader('Cache-Control', 'value_you_prefer')`

docs/going-to-production.md Outdated Show resolved Hide resolved
balazsorban44
balazsorban44 previously approved these changes Mar 16, 2022
Copy link
Member

@balazsorban44 balazsorban44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


If the page is using `getServerSideProps` or `getInitialProps`, then it will use the default `Cache-Control` header configured by `next start` in order to prevent accidental caching of responses that cannot be cached. If you want a different cache behavior while using SSR you can use `res.setHeader('Cache-Control', 'value_you_prefer')`.

If the page is using `getStaticProps` or automatic static optimization, then it will have s-maxage=REVALIDATE_SECONDS, stale-while-revalidate or if revalidate is not used s-maxage=31536000, stale-while-revalidate.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stale-while-revalidate header is not set for pages that are automatically statically optimized, only pages that use getStaticProps and return a revalidate value.

kodiakhq bot pushed a commit that referenced this pull request Mar 16, 2022
Follow up on #35336 based on suggestions I would have made pre-merge.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: Add section about how cache-control headers are set, depending on how your pages fetch data
3 participants